﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;
namespace DuJianliang.ApplicationPlatform.Proj5715.Process
{
    public partial class FaultEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                ViewState["DispatchMissileProcessID"] = Request.QueryString["DispatchMissileProcessID"].Trim();

                var dal = new ProcessDal();
                DispatchMissileProcessOB obj = dal.GetDispatchMissileProcessById(ViewState["DispatchMissileProcessID"].ToString());
                if (!string.IsNullOrEmpty(obj.SectionCode))
                {
                    Isfault.Checked = obj.IsFault.ToLower() == "true" ? true : false;
                    txt_FaultReson.Text = obj.FaultReason;
                    txt_Remark.Text = obj.Remark;

                }
            }
        }

        protected void btn_OK_Click(object sender, EventArgs e)
        {
            int isFault = Isfault.Checked ? 1 : 0;

            string strFaultReson = txt_FaultReson.Text.Trim();
            string strRemark = txt_Remark.Text.Trim();

            string sql = "UPDATE t5715_DispatchMissileProcess " +
                       "SET  IsFault = " + isFault + ", " +
                         "FaultReason='" + strFaultReson + "',Remark='" + strRemark + "'" +
                       " WHERE DispatchMissileProcessID ='" + ViewState["DispatchMissileProcessID"].ToString() + "'";

            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetSqlStringCommand(sql);
                database.ExecuteNonQuery(dbCommand);

                Response.Write("<script>window.opener = null;window.open('', '_self', '');window.close();</script>");
            }
            catch (Exception exp)
            {
                throw exp;
            }


        }
    }
}